import Vue from 'vue'
import Router from 'vue-router'
import Index from "./views/Index.vue"
import Login from "./views/login/index.vue"
import allclass from "./views/class/allclass.vue"
import typeclass from "./views/class/typeclass.vue"
import secure from "./views/class/secure.vue"
import course from "./views/class/course.vue"
import fenzu from "./views/class/fenzu.vue"
import sections from "./views/class/sections.vue"
import messages from "./views/secure/message.vue"
import scratch from "./views/scratch/index.vue"
const my = {
  download: () => import('@/home/views/myhome/download'),
  index: () => import('@/home/views/myhome/index'),
  learningcard: () => import('@/home/views/myhome/learningcard'),
  order: () => import('@/home/views/myhome/order'),
  presentation: () => import('@/home/views/myhome/presentation'),
  setup: () => import('@/home/views/myhome/setup'),
  myinfo: () => import('@/home/views/myhome/myinfo'),
  mypasswold: () => import('@/home/views/myhome/mypasswold'),
  mywx: () => import('@/home/views/myhome/mywx'),
  mymedal: () => import('@/home/views/myhome/mymedal'),
  myuser: () => import('@/home/views/myhome/myuser'),
  myinvitation: () => import('@/home/views/myhome/myinvitation'),
  Avatar: () => import('@/home/views/myhome/Avatar'),
}
const list = {
  scetionw: () => import('@/home/views/class/scetionw'),
  myindex: () => import('@/home/views/aliplayer/index'),
}


import {
  get
} from "jquery"
Vue.use(Router)

export default new Router({
  routes: [{
    path: '/',
    name: 'index',
    component: Index,
    //重定向
    redirect: '/myclass',
    children: [{
      path: "/secure",
      name: 'secure',
      component: secure,
      redirect: '/myclass',
      children: [{
        path: '/myclass',
        name: 'myclass',
        component: my.index,
      },
      {
        path: 'download',
        name: 'download',
        component: my.download,
      },
      {
        path: 'learningcard',
        name: 'learningcard',
        component: my.learningcard,
      },
      {
        path: 'order',
        name: 'order',
        component: my.order,
      },
      {
        path: 'presentation',
        name: 'presentation',
        component: my.presentation,
      },
      {
        path: 'setup',
        name: 'setup',
        component: my.setup,
        redirect: {
          name: 'myinfo'
        },
        children: [{
          path: 'myinfo',
          name: 'myinfo',
          component: my.myinfo,
        },
        {
          path: 'Avatar',
          name: 'Avatar',
          component: my.Avatar,
        },
        {
          path: 'mypasswold',
          name: 'mypasswold',
          component: my.mypasswold,
        },
        {
          path: 'mywx',
          name: 'mywx',
          component: my.mywx,
        },
        {
          path: 'mymedal',
          name: 'mymedal',
          component: my.mymedal,
        },
        {
          path: 'myuser',
          name: 'myuser',
          component: my.myuser,
        },
        {
          path: 'myinvitation',
          name: 'myinvitation',
          component: my.myinvitation,
        },
        ]
      },
      ]
    },
    {
      path: "/allclass",
      name: 'allclass',
      component: allclass
    },
    {
      path: "/typeclass/:id",
      name: 'typeclass',
      component: typeclass,
      props: true
    },
    {
      path: "/course/:ktId",
      name: 'course',
      component: course,
      props: true
    },
    {
      path: "/fenzu/:fenzuId",
      name: 'fenzu',
      component: fenzu,
      props: true
    },
    {
      path: "/sections/:cid/:num",
      name: 'sections',
      component: sections,
      redirect: '/sections/:cid/:num',
      props: true,
      children:[
        {
        path: '',
      components:{
        'aliplayer':list.myindex,
        'scetionw':list.scetionw
      },
      props: true,
      }
    ]
    },
    {
      path: "/messages",
      name: 'messages',
      component: messages
    },
    {
      path: '/scratch/:cid/:num',
      name: 'scratch',
      component: scratch,
      redirect: '/scratch/:cid/:num',
      props: true,
      children:[  
        {
        path: '',
        component:list.myindex,
        },
      ]
    },

    ]
  },
  {
    path: '/login',
    name: 'login',
    component: Login,
  },
  {
    //服务器退出 
    path: '/logout',
    name: 'logout',
    beforeEnter: function (to, from, next) {
      get("/user/logout")
      next("/login")
      location.href = "/"
    }
  },
    // {
    //   path: '/kctx',
    //   name: 'kctx',
    //   component: kctx
    // }
  ]
});